home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / dict / sortseq.c < prev   
C/C++ Source or Header  |  1994-08-05  |  1KB  |  86 lines

  1. #include <LEDA/sortseq.h>
  2. #include <LEDA/stream.h>
  3.  
  4.  
  5. void print(sortseq<string,int>& S)
  6. { seq_item it;
  7.   cout << S.size() << endl;
  8.   forall_items(it,S) cout << S.key(it) << endl;
  9.   newline;
  10. }
  11.  
  12. void print1(sortseq<string,int> S)
  13. {
  14.   cout << S.size() << endl;
  15.   while( !S.empty() )
  16.   { seq_item it = S.min();
  17.     cout << S.key(it) << endl;
  18.     S.del_item(it);
  19.    }
  20.   newline;
  21. }
  22.  
  23.  
  24. main()
  25. {
  26.   sortseq<string,int> S,S1,S2;
  27.  
  28.   file_istream input(read_string("file name: "));
  29.  
  30.   string s;
  31.  
  32.   while (input >> s)  S.insert(s,0);
  33.  
  34.   cout << S.size() << " strings.\n\n";
  35.  
  36.  
  37. cout << "print: " << endl;
  38.   print(S);
  39.  
  40. cout << "print1: " << endl;
  41.   print1(S);
  42.  
  43.   string s1,s2;
  44.  
  45.   do { s1 = read_string("s1 = ");
  46.  
  47.        s2 = read_string("s2 = ");
  48.  
  49.        if (s1 > s2) 
  50.         { cerr << "illegal input: s1 > s2.\n";
  51.           continue;
  52.          }
  53.  
  54.        seq_item it1 = S.locate(s1);
  55.  
  56. /*
  57.        cout << "SPLIT at " << S.key(it1) << "\n";
  58.        newline;
  59. */
  60.  
  61.        seq_item it2 = S.locate(s2);
  62.      
  63.        while (it1!=it2)
  64.          { cout << S.key(it1) << "\n"; 
  65.            it1 = S.succ(it1);
  66.           }
  67.  
  68. /*
  69.        S.split(it1,S1,S2);  //now S is mepty
  70.  
  71.        print(S1);
  72.  
  73.        print(S2);
  74.  
  75.        S1.conc(S2);         //now S2 is empty
  76.  
  77.        S.conc(S1);          //now S1 is empty
  78. */
  79.  
  80.  
  81.      } while (s1 != "");
  82.     
  83.  
  84.   return 0;
  85. }
  86.